package com.dweb.myjsdemo.widget.widget;

import com.dweb.myjsdemo.widget.controller.FormController;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.FormBindingData;
import ohos.aafwk.ability.ProviderFormInfo;
import ohos.aafwk.content.Intent;
import ohos.app.Context;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
import ohos.utils.zson.ZSONObject;


public class WidgetImpl extends FormController {
  private static final HiLogLabel TAG = new HiLogLabel(HiLog.DEBUG, 0x0, WidgetImpl.class.getName());
  private static final int DIMENSION_1X2 = 1;
  private static final int DIMENSION_4X4 = 4;

  public WidgetImpl(Context context, String formName, Integer dimension) {
    super(context, formName, dimension);
  }

  @Override
  public ProviderFormInfo bindFormData() {
    HiLog.info(TAG, "bind form data");
    ZSONObject zsonObject = new ZSONObject();
    ProviderFormInfo providerFormInfo = new ProviderFormInfo();
    if (dimension == DIMENSION_1X2) {
      zsonObject.put("mini", true);
    }
    if (dimension == DIMENSION_4X4) {
      zsonObject.put("imagePaddingTop", "12px");
    }
    providerFormInfo.setJsBindingData(new FormBindingData(zsonObject));
    return providerFormInfo;
  }

  @Override
  public void updateFormData(long formId, Object... vars) {
    HiLog.info(TAG, "update form data timing, default 30 minutes");
  }

  @Override
  public void onTriggerFormEvent(long formId, String message) {
    HiLog.info(TAG, "handle card click event.");
  }

  @Override
  public Class<? extends AbilitySlice> getRoutePageSlice(Intent intent) {
    HiLog.info(TAG, "get the default page to route when you click card.");
    return null;
  }
}
